# 文件名hello.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import json

app = Flask(__name__)
# app.config['SECRET_KEY'] = 'Fianna'
app.config[
    'SQLALCHEMY_DATABASE_URI'] = 'mysql://pig:123@192.168.99.101:3306/employees'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
db = SQLAlchemy(app)

class Titles(db.Model):
    __tablename__ = 'titles'
    emp_no = db.Column(db.Integer, nullable=False, primary_key=True)
    title = db.Column(db.String(50), nullable=False, primary_key=True)
    from_date = db.Column(db.DateTime, nullable=False, primary_key=True)
    to_date = db.Column(db.DateTime, nullable=False)

    def __init__(self, no, tl, fr, to):
        self.emp_no = no
        self.title = tl
        self.from_date = fr
        self.to_date = to

    def __repr__(self):
        return '<Role %r>' % self.emp_no


# class User(db.Model):
#     __tablename__ = 'users'
#     id = db.Column(db.Integer, nullable=False, primary_key=True, autoincrement=True)
#     username = db.Column(db.String(32), nullable=False, unique=True, server_default='', index=True)
#     role_id = db.Column(db.Integer, nullable=False, server_default='0')

if __name__ == '__main__':
    ol = Titles.query.filter_by(emp_no=10001).all()
    print ol[0].emp_no
    #jsonstr =
    #ol[0]['emp_no']
    print "hello world"
    me = Titles(123456, "123", '1920-10-13', '1940-10-13')
    print db.session.add(me)
    print db.session.commit()
    print "12"